package com.atguigu.rabbit.producer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Worker Hu
 * @CreateTime: 2024-07-23  16:45
 */
@Configuration
public class RabbitConfig2 {

    // 声明交换机
    @Bean
    public Exchange directExchange() {
        Exchange directExchange = ExchangeBuilder.directExchange("direct_exchange01").durable(true).build();
        return directExchange ;
    }

    // 声明队列
    @Bean
    public Queue directQueue01() {
        Queue queue = QueueBuilder.durable("direct_queue_01").build();
        return queue ;
    }

    // 声明队列
    @Bean
    public Queue directQueue02() {
        Queue queue = QueueBuilder.durable("direct_queue_02").build();
        return queue ;
    }

    // 声明队列和交换机的绑定信息
    @Bean
    public Binding directQueue01Binding() {
        Binding binding = BindingBuilder.bind(directQueue01()).to(directExchange())
                .with("error").noargs();
        return binding ;
    }

    @Bean
    public Binding bindingQueue02BindingErrorRoutingKey() {
        Binding binding = BindingBuilder.bind(directQueue02()).to(directExchange())
                .with("error").noargs() ;
        return binding ;
    }

    @Bean
    public Binding bindingQueue02BindingInfoRoutingKey() {
        Binding binding = BindingBuilder.bind(directQueue02()).to(directExchange())
                .with("info").noargs() ;
        return binding ;
    }

}


